JavaScript Array []

Definition and Usage

[ ] The constructor is used to create a new array object.

Instance

Example 1

// Create an array
const cars = ["Saab", "Volvo", "BMW"];

Try It Yourself

Example 2

Create an empty array and add values:

// Create an array
const cars = [];
// Add values to the array
cars.push("Saab");
cars.push("Volvo");
cars.push("BMW");

Try It Yourself

Example 3

Using new Array() Method to create an array:

// Create an array
const cars = new Array(["Saab", "Volvo", "BMW"]);

Try It Yourself

Syntax

[iterable]

Parameter

Parameter Description
iterable Required. An iterable object containing values.

Return Value

Type Description
Array New Array Object

Browser Support

[] The array constructor is a feature of ECMAScript1 (JavaScript 1997).

It is supported in all browsers:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support